package com.duck.user.controller;

import com.duck.common.domain.Result;
import com.duck.common.utils.UserContext;
import com.duck.user.domain.dto.ChangeUserInfoDto;
import com.duck.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.HashMap;

@RequestMapping("/user")
@RestController
public class ChangeUserInfoController {

    @Autowired
    private UserService userService;

    /**
     * 修改个人信息(修改头像，地址，性别)
     * @param user 前端入参
     * @return 状态码
     */
    @PostMapping("/changeUserInfo/")
    public Result changeUserInfo(@NotNull @RequestBody ChangeUserInfoDto user){
        //获取用户ID
        String userId = String.valueOf(UserContext.getUser());
        //修改个人信息
        HashMap<String, Object> info = new HashMap<>() {{
            put("avatar", user.getAvatar());
            put("userId", userId);
            put("province", user.getProvince());
            put("city", user.getCity());
            put("district", user.getDistrict());
            put("introduce", user.getIntroduce());//介绍自己擅长什么
            put("affiliation", user.getAffiliation());//归属
        }};
        userService.changeUserInfo(info);
        return new Result(200,"修改成功");
    }
}
